package com.github.edu.web.role.controller;

import com.github.admin.edu.assembly.common.entity.JsonArray;
import com.github.admin.edu.assembly.page.entity.Pager;
import com.github.admin.edu.oauth.server.api.entity.TSysRole;
import com.github.edu.client.common.annotation.*;
import com.github.edu.client.common.controller.BaseController;
import com.github.edu.web.role.service.RoleManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by IntelliJ IDEA.
 * user:wangj
 * date:2018/8/12
 * Time: 9:37
 */
@Controller
@RequestMapping("/uc/role")
public class RoleManagerController extends BaseController<TSysRole,Long> {

    @Autowired
    private RoleManagerService service;

    @QueryAll
    public String index(ModelMap modelMap, TSysRole sysOauth, Pager pager) {
        if(null==pager){
            pager=new Pager();
        }
        pager.setDirection("ASC");
        String[] strs={"id"};
        pager.setOrder(strs);
        JsonArray<TSysRole> jsonArray=service.getAllByPage(sysOauth,pager);
        return super.index(modelMap,sysOauth,jsonArray,"role","角色管理",
                "编码:id","角色名称:name","角色编码:code","当前状态:stateName");
    }

    @New
    public String add(ModelMap modelMap, TSysRole sysOauth, HttpServletRequest request) {
        return super.newIndex(modelMap,sysOauth,"role","保存角色信息");
    }

    @Save
    public String saveOrUpdate(ModelMap modelMap, TSysRole sysOauth, HttpServletRequest request) {
        sysOauth=service.saveOrUpdate(sysOauth);
        return super.saveObject(modelMap,sysOauth,"保存成功！","role","保存角色");
    }

    @Open
    public String openEntity(ModelMap modelMap,@PathVariable("id") Long id) {
        TSysRole application=service.getEntity(id);
        return super.openEntity(modelMap,application,"role","查看详情");
    }
    @Edit
    public String edit(ModelMap modelMap,@PathVariable("id") Long s) {
        TSysRole application=service.getEntity(s);
        return super.newIndex(modelMap,application,"role","修改角色");
    }

    @Delete
    public String delete( String ids) {
        return service.delete(ids);
    }

}
